<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <style>
    	body{
    	background-color: #FFFFFF;
    		
    	}
    	.win_wid{
    		width: 100%;
    		height: auto;
    	}
    	.text_name_win{
    		width: auto;
    		height: auto;
    		background-color: #FFFFFF;
    	}
    	.top_bar{
    		width:100%;
    		height: 44px;
    		line-height: 44px;
    		background-color: #18B4ED
    		
    	}
    	.top_img{	
    		float:left;
    	}
    	.top_text{
    		float:right;
    	}
    	.top_bar img{
    		position:absolute;
    		height: 22px;
    		top:11px;
    		left:15px;
    	}
    	.top_bar p{
    		font-size: 20px;
    		text-align: center;
    		color:#FFFFFF;
    	}
    	.top_bar span{
    		position:absolute;
    		font-size: 18px;
    		color:#FFFFFF;
    		right: 15px;
    		top:0px;
    	}
    	.list_name{
    		width: 100%;
    		background-color: #FFFFFF;
    	}
    	.list_name img{
    		width: 20px;
    		height: 20px;
    	}
    	table{
    		width: 100%;    		
    	}
    	.trs{
    		border-top:1px solid #A5A5A5;
    	}
    	.tds{
    		/*border-right:1px solid #A5A5A5;*/
    		background-color: #d9d9d9;
    		font-size: 18px;
    		text-align: center;
    		height:40px;
    		line-height: 40px;
    	}
    </style>
</head>
<body>
<div class="win_wid">
	<div class="top_bar"> 
		<a class="top_img"> <img src="../../image/icon_jiantou.png" onclick="backClick()"/></a>
		<p> 学生选择</p>
		<a class="top_text" onclick="add_stu()"><span>确定</span></a>
	</div>
	<div class="text_name_win" id="stu_name">
		<p style="padding: 10px">请选择:</p>
		<p id="text_name" style="padding: 10px">暂无人员</p>
	</div>
	<div class="list_name" id="list_d">
		<table id="lists">
    	<tr class="trs">
    	<td class="tds" style="width: 80px"> <img style="vertical-align:middle;" src="../../icon/checkbutton_unselectd.png" id="imgsb" onclick="checks()"/> </td>
    	<td class="tds" style="background-color:#646464;width: 100px">姓名</td>
    	<td class="tds"><span id="spteam">全部分组</span><img style="vertical-align:middle;width: 15px;height: 10px;" src="../../icon/down_icon.png" id="downlist" onclick="dnlist()"/></td>
    	</tr>
    	</table>
	</div>
</div>
</body>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
    <script src="../../script/common.js"></script>
	<script src="../../script/timeStampTool.js"></script>
	<script src="../../script/processing_images.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/mui.min.js"></script>
<script type="text/javascript">
	var uids = "";
	var luid = "";
	var lpid = "";
	var lvid = "";
	var ljid = "";
	var ischecks = false;
	var openteamlist = false;
	var datae = new Object();
	apiready = function(){
		lvid = api.pageParam.vid;
		luid = api.pageParam.uid;
		ljid = api.pageParam.jid;
		lpid = api.pageParam.pid;
		lcid = api.pageParam.cid;
		var params = {
				vid:lvid,
				uid:luid,
				jid:ljid,
				pid:lpid,
				cid:lcid	
		};	
//		var url_cf = "http://base.cfnet.org.cn/course/Sitenow_Normal/getSitenowScorelist";
		showProgress();
		cfnetppPOST(url_getSitenowScorelist, params, true, function(data, status) {
			hideProgress();
//			alert(JSON.stringify(data));
			datae = data;
			if(status == 'success'){
				var stuNameHeight = document.getElementById("stu_name").offsetHeight;
				api.openFrame({
	        		name: 'new_stulist',
	       			url: 'new_List_stu_check.html',
	        		pageParam:{
	        			data:datae
	        		},
	        		rect: {
		        		x:0,
		        		y:stuNameHeight + 84,
		        		w:api.winWidth,
		        		h:'auto'
	        		}
        });
			}else{
				api.toast({
	                msg:'网络请求出错，请重试！'
                });
                api.closeFrame({
    				name: 'new_Stulist'
				});
//				$('#noNet').show();
			}
		});
		
        t = document.getElementById("stu_name");
		t.style.visibility="hidden"; 
		d = document.getElementById("list_d");
		d.style.visibility="hidden";
		api.addEventListener({
	        name:'list_team_open'
        },function(ret,err){
        	//coding...
        	openteamlist = false;
        });
		// 监听小组变化
		api.addEventListener({
	        name:'checked_lis'
        },function(ret,err){
        	//coding...
        	var values = ret.value; 
        	uids = "";
        	nase = document.getElementById("text_name");
        	nase.innerHTML = "暂无人员";
        	nases = document.getElementById("spteam");
        	nases.innerHTML = values.team_name;
        	
        });
		// 设置全选按钮可以点击
		api.addEventListener({
	        name:'ischecks'
        },function(ret,err){
        	//coding...
        	ischecks = true;
        });
        // 监听是否全选
        api.addEventListener({
	        name:'allchecks'
        },function(ret,err){
        	//coding...
        	imgs = document.getElementById('imgsb');
        	imgs.src = "../../icon/checkbutton_selectd.png";
        	
        });
		// 监听控件显示
		api.addEventListener({
		    name:'hidep'
    	},function(ret,err){
    		var values = ret.value; 
    		if(values.visi == "1"){
    		t = document.getElementById("stu_name");
			t.style.visibility="visible"; 
			d = document.getElementById("list_d");
			d.style.visibility="visible";
    	}

 	   });
 	   // 监听人员选择
  	  api.addEventListener({
		    name:'d_se'
  	  },function(ret,err){
   		  //coding...
    	  var names = ret.value;
//  	  uids = 
    	  uids = uids + names.uid + ',';
    	  chage_stu_name(names.name);
 	  });
    // 监听人员取消
 	api.addEventListener({
	  name:'d_un'
    },function(ret,err){
    	var names = ret.value;
    	uids = uids.replace(names.uid + ',','')
    	clean_stu_name(names.name);
    });
    // 监听人员全选
    api.addEventListener({
	    name:'all_se'
    },function(ret,err){
    	//coding...
    	var values = ret.value;
    	pp = document.getElementById("text_name");
    	pp.innerHTML = values.all;
    	uids = values.alluid;
    	chage_layout();
    });
    // 改变全选按钮的状态
    api.addEventListener({
	    name:'unselect'
    },function(ret,err){
    	//coding...
    	imgs = document.getElementById('imgsb');
    	imgs.src = "../../icon/checkbutton_unselectd.png";
    });
    // 监听人员全部取消
	api.addEventListener({
	    name:'all_un'
    },function(ret,err){
    	pp = document.getElementById("text_name");
    	pp.innerHTML = "暂无人员";
    	uids = "";
    	chage_layout();
    });
    // 设置选择人员显示
    nase = document.getElementById("text_name");
    var ns = $api.getStorage('stu_names');
    if(ns == ""){
    	
    }else{
    	nase.innerHTML = ns;
    	chage_layout();
    }
	};
	
	//关闭学生列表窗口
	function backClick(){
		api.closeWin({
        });
	}
	// 添加人员
	function chage_stu_name(stu_names){
		nase = document.getElementById("text_name");
		var nss = nase.innerHTML
		if(nss == "暂无人员"){
			nase.innerHTML = stu_names;
			
		}else{
			nase.innerHTML = nase.innerHTML + "、" + stu_names;
		}
		chage_layout();

	}
	// 删除人员
	function clean_stu_name(stu_names){
		nase = document.getElementById("text_name");
		var nar = nase.innerHTML + "、";
		var as = nar.replace(stu_names + "、","");
		if(as == ""){
			nase.innerHTML = "暂无人员";
		}else{
			nase.innerHTML = as.substring(0,as.length - 1);
		}
		chage_layout();
		
	}
	function dnlist(){
		if(openteamlist){
			// 如果frame以及打开，再次点击按钮，关闭frame
			openteamlist = false;
			api.sendEvent({
	        	name:'mark',
	        	extra:{'name':"0"}
        	});
        	api.closeFrame({
    			name: 'check_lis'
			});
		}else{
			api.sendEvent({
	        	name:'mark',
	        	extra:{'name':"1"}
        	});
        	openteamlist = true;
        	var stuNameHeights = document.getElementById("stu_name").offsetHeight;
        	api.openFrame({
	        	name: 'check_lis',
	        	url: 'check_list.html',
	        	rect: {
		        	x:0,
		        	y:stuNameHeights + 84,
		        	w:api.winWidth,
		        	h:280
	        	}
        	});
		}
		
		
		
	}
	function checks(){
		if(ischecks){
			imgs = document.getElementById('imgsb');
			if(imgs.src.match("checkbutton_unselectd")){
				imgs.src = "../../icon/checkbutton_selectd.png";
				api.sendEvent({
	           	 name:'all_ses'
            	});
			}else{
				imgs.src = "../../icon/checkbutton_unselectd.png";
				api.sendEvent({
	            	name:'all_uns'
            	});
			}
		}
		
	}
	function chage_layout(){
		var stuNameHeight = document.getElementById("stu_name").offsetHeight;
		api.setFrameAttr({
	        name: 'stulist',
	        rect: {
	        	x:0,
		        y:(stuNameHeight + 84),
		        w:api.winWidth,
		        h:'auto'
	        }
        });
	}
	function add_stu(){
		pp = document.getElementById("text_name");
		$api.setStorage('stu_list_uid',uids);
//		alert($api.getStorage('stu_list_uid'));
		$api.setStorage('stu_names',pp.innerHTML);
//		alert($api.getStorage('stu_names'));
		api.closeWin({
        });
	}
</script>
</html>